const { graphql, buildSchema, GraphQLSchema, GraphQLObjectType, GraphQLString } = require('graphql');


const http = require('http');
const fs = require('fs');

const schema = buildSchema(`
  type Query {
    hello: String
  }
`);

const root = {
  hello: () => 'hello world'
}

const server = http.createServer(async (req, res) => {

  if (req.url === '/') {
    fs.readFile('./index.html', (err, data) => {
      res.end(data);
    });
  } else if (req.url === '/graphql') {
    const values = await graphql({ schema, rootValue: root });
    console.log(values);
    res.end(JSON.stringify(values));
  }

});

server.listen(3001, () => {
  console.log('server at http://localhost:3001')
});
